﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;

///<summary>
///计分
///</summary>
public class PlayerDataManager
{

    int curusePoint;
    int curMoney = 0;
    int bestScore = PlayerPrefs.GetInt("BestScore");
    int totalMoney = PlayerPrefs.GetInt("TotalMoney");

    static PlayerDataManager intance;
    public static PlayerDataManager GetIntance()
    {
        if (intance == null)
        {
            intance = new PlayerDataManager();
        }
        return intance;
    }
    private PlayerDataManager() { }
    public void Init()
    {
        curusePoint = 0;
    }
    public int GetPoint()
    {
        return curusePoint;
    }
    public void AddPoint(int point)
    {
        curusePoint += point;
    }    
    public void AddMoney(int num)
    {
        curMoney += num;
    }
    public int GetBestScore()
    {
        return bestScore;
    }
    public int GetTotalMoney()
    {
        return totalMoney;
    }

    public bool SubMoney(int num)
    {
        if (num > totalMoney)
        {
            Debug.Log("请充值，金币不够");
            return false;
        }
        totalMoney -= num;
        return true;
    }

    public int GetMoney()
    {
        return curMoney;
    }

    public void Clear()
    {
        curMoney = 0;
        curusePoint = 0;
    }

    public void ScoreClose()
    {
        bestScore = bestScore > curusePoint ? bestScore : curusePoint;
        PlayerPrefs.SetInt("BestScore", bestScore);
        totalMoney += curMoney;
        PlayerPrefs.SetInt("TotalMoney", totalMoney);
    }
}
